{template '_header'}
<div style="margin-top: 50px"></div>

<form action="" method="post" class="form-horizontal form-search form-validate">
    <h3>砍价活动编辑</h3>
    <hr>
    <div class="form-group">
        <label class="col-sm-2 control-label">商品标题</label>
        <div class="col-sm-9 col-xs-12">
            <input type="text" name="title" class="form-control" value="{$this_goods['title']}" readonly="readonly">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">商品标价</label>
        <div class="col-sm-9 col-xs-12">
            <div class="input-group" style="width: 200px">
                <input type="text" name="marketprice" id="marketprice" class="form-control" value="{$this_goods['marketprice']}" readonly>
                <span class="input-group-addon">元</span>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label must">设置底价</label>
        <div class="col-sm-9 col-xs-12">
            <div class="input-group" style="width: 200px">
                <input type="text" name="end_price" class="form-control" value="{$this_act['end_price']}" required="requied" onkeyup="this.value=/^\d+\.?\d{0,2}$/.test(this.value) ? this.value : ''">
                <span class="input-group-addon">元</span>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">显示底价</label>
        <div class="col-sm-9 col-xs-12">
            <label class="radio-inline">
                <input type="radio" name="display" value="0" class="valid" {if $this_act['type']==0}checked{/if} /> <s></s>不显示
            </label>
            <label class="radio-inline">
                <input type="radio" name="display" value="1" class="valid" {if $this_act['type']==1}checked{/if} /> 显示
            </label>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">没到底价</label>
        <div class="col-sm-9 col-xs-12">
            <label class="radio-inline">
                <input type="radio" name="order_set" value="0" class="valid" {if $this_act['mode']==0}checked{/if} > 可以下单
            </label>
            <label class="radio-inline">
                <input type="radio" name="order_set" value="1" class="valid" {if $this_act['mode']==1}checked{/if} > 不可下单
            </label>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">自己砍价</label>
        <div class="col-sm-9 col-xs-12">
            <label class="radio-inline">
                <input type="radio" name="myself" value="1" aria-invalid="false" class="valid" {if $this_act['myself']==1}checked{/if}> 允许
            </label>
            <label class="radio-inline">
                <input type="radio" name="myself" value="0"  class="valid" aria-invalid="false" {if $this_act['myself']==0}checked{/if}> 禁止
            </label>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">发起次数</label>
        <div class="col-sm-9 col-xs-12">
            {if $this_act['initiate']==0}
            <label class="radio-inline">
                <label style="color: #ff3f4b">允许多次发起同一个商品的砍价</label>
            </label>{/if}{if $this_act['initiate']==1}
            <label class="radio-inline">
                <label style="color: #ff3f4b">每个商品只允许发起一次砍价</label>
            </label>{/if}
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">活动时间</label>
        <div class="col-sm-9 col-xs-12">
            {php $time = array('start'=>$this_act['start_time'],'end'=>$this_act['end_time']);}
            {php echo tpl_form_field_daterange('act_time',$time, true);}
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">砍价时限</label>
        <div class="col-sm-9 col-xs-12">
            <div class="input-group" style="width: 200px">
                <input type="number" name="time_limit" class="form-control" value="{$this_act['time_limit']}">
                <span class="input-group-addon">小时</span>
            </div>
        </div>
    </div>
    <hr>
    <div class="form-group">
        <label class="col-sm-2 control-label">可砍价总次数</label>
        <div class="col-sm-9 col-xs-12">
            <div class="input-group" style="width: 200px">
                <input type="number" name="total_time" class="form-control" value="{$this_act['total_time']}">
                <span class="input-group-addon">次</span>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">每人可砍次数</label>
        <div class="col-sm-9 col-xs-12">
            <div class="input-group" style="width: 200px">
                <input type="number" name="each_time" class="form-control" value="{$this_act['each_time']}">
                <span class="input-group-addon">次</span>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">活动可发起次数</label>
        <div class="col-sm-9 col-xs-12">
            <div class="input-group" style="width: 200px">
                <input type="number" name="total_act" class="form-control" value="{$this_act['maximum']}">
                <span class="input-group-addon">次</span>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">每次砍价概率</label>

        <div class="col-sm-9 col-xs-12" id="addrand">

            <div id="aad">
                <span style="color: #ff3f4b">
                    最大增加金额用正数表示，例如：6 ，
                    最大减少金额用负数表示，例如：-6 ，概率相加必须等于100%</span>

                {php $count = 0;}
            {loop $tt['rand'] $key $value}
            <div class="input-group" style="margin-top: 10px;margin-bottom: 10px" id="input-group">
                <input type="number" name="rand_left[]" class="form-control" value="{$tt['min'][$count]}">
                <span class="input-group-addon">元 &nbsp;&nbsp;&nbsp;至</span>
                <input type="number" name="rand_right[]" class="form-control" value="{$tt['max'][$count]}">
                <span class="input-group-addon">元 &nbsp;&nbsp;&nbsp;概率</span>
                <input type="text" name="rand[]" id="costprice" class="form-control" value="{$tt['rand'][$count]}" onkeyup="this.value=/^\d+$/.test(this.value) ? this.value : ''">
                <span class="input-group-addon">%</span>
            </div>
            {php $count++;}
            {/loop}
            </div>
        </div>
        <div style="padding-top: 50px"><a class="btn btn-primary" onclick="addlink()" style="margin-left: 160px">添加区间</a>
            <a class="btn btn-primary" onclick="myFunction()" style="margin-left: 160px">删除区间</a></div>
        <script>
            function myFunction() {
                var p = document.getElementById('aad');
                p.removeChild(document.getElementById('input-group'));
            }
        </script>
        <script>
            function addlink(){
                var html ='<div class="input-group" style="margin-top: 10px;margin-bottom: 10px" id="input-group">';
                html+='<input type="number" name="rand_left[]" id="marketprice" class="form-control">';
                html+='<span class="input-group-addon">元 &nbsp;&nbsp;&nbsp;至</span>';
                html+='<input type="number" name="rand_right[]" id="productprice" class="form-control">';
                html+='<span class="input-group-addon">元 &nbsp;&nbsp;&nbsp;概率</span>';
                html+='<input type="text" name="rand[]" id="costprice" class="form-control" value="" onkeyup="this.value=/^\d+$/.test(this.value) ? this.value : ">';
                html+='<span class="input-group-addon">%</span>';
                html+='</div>';
                $('#aad').append(html);
            }
        </script>
    </div>
    <hr>
    <div class="form-group">
        <label class="col-sm-2 control-label">【分享】商品标题</label>
        <div class="col-sm-9 col-xs-12">
            <input type="text" name="goods_share_title" class="form-control" value="{$user_set['goods_title']}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">【分享】商品描述</label>
        <div class="col-sm-9 col-xs-12">
            <input type="text" name="goods_share_describe" class="form-control" value="{$user_set['goods_content']}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">【分享】商品图片</label>
        <div class="col-sm-9 col-xs-12">
            {php echo tpl_form_field_image(goods_share_logo,$user_set['goods_logo']);}
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">【分享】砍价标题</label>
        <div class="col-sm-9 col-xs-12" name="form1">
            砍价标题模板标签: <a onclick="addtext0()"> [原价]</a><a onclick="addtext1()"> [现价]</a><a onclick="addtext2()"> [底价]</a><a onclick="addtext3()"> [已砍]</a><a onclick="addtext4()"> [未砍]</a><br>
            <input type="text" name="bargain_share_title" class="form-control" id="moban" value="{$user_set['bargain_title']}">
        </div>
    </div>

    <script language="javascript">
        <!--
        function addtext0(){
            var str = "[原价]";
            var txt = document.getElementById('moban').value;
            txt = txt + "\r" + str;
            document.getElementById('moban').value = txt;
        }
        function addtext1(){
            var str = "[现价]";
            var txt = document.getElementById('moban').value;
            txt = txt + "\r" + str;
            document.getElementById('moban').value = txt;
        }
        function addtext2(){
            var str = "[底价]";
            var txt = document.getElementById('moban').value;
            txt = txt + "\r" + str;
            document.getElementById('moban').value = txt;
        }
        function addtext3(){
            var str = "[已砍]";
            var txt = document.getElementById('moban').value;
            txt = txt + "\r" + str;
            document.getElementById('moban').value = txt;
        }
        function addtext4(){
            var str = "[未砍]";
            var txt = document.getElementById('moban').value;
            txt = txt + "\r" + str;
            document.getElementById('moban').value = txt;
        }
        //-->
    </script>
    <div class="form-group">
        <label class="col-sm-2 control-label">【分享】砍价描述</label>
        <div class="col-sm-9 col-xs-12">
            <input type="text" name="bargain_share_describe" class="form-control" value="{$user_set['bargain_content']}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">【分享】砍价图片</label>
        <div class="col-sm-9 col-xs-12">
            {php echo tpl_form_field_image(bargain_share_logo,$user_set['bargain_logo']);}
        </div>
    </div>


    <div class="form-group">
        <label class="col-sm-2 control-label">砍价规则</label>
        <div class="col-sm-9 col-xs-12">
            <label class="radio-inline">
                <input type="checkbox" name="bang_swi" value="1" aria-invalid="false" class="valid" onclick="check()" id="bang" {if $this_act['rule'] == null}checked{/if}> 使用全局规则
            </label>
        </div>
    </div>

    <div class="form-group" style="display: none;" id="partin">
        <label class="col-sm-2 control-label">砍价规则设置</label>
        <div class="col-sm-9 col-xs-12">
            {php echo tpl_ueditor('rule',$this_act['rule']);}
        </div>
    </div>
    <script>

        check();
        function check() {
            var res = document.getElementById("bang").checked;
            if(res){
                document.getElementById("partin").style.display = "none";
            }else{
                document.getElementById("partin").style.display = "block";
            }
        }
    </script>



    <div class="form-group">
        <label class="col-sm-2 control-label">倒计时前的文字</label>
        <div class="col-sm-9 col-xs-12">
            <div class="input-group" style="width: 200px">
                <input type="text" name="countdown" class="form-control" maxlength="6" value="{$this_act['custom']['countdown']}">
                <span class="input-group-addon"><input type="color" name="countdown_color" value="{$this_act['custom']['countdown_color']}"></span>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">砍多少减多少文字</label>
        <div class="col-sm-9 col-xs-12">
            <div class="input-group" style="width: 200px">
                <input type="text" name="cutmore" class="form-control" maxlength="6" value="{$this_act['custom']['cutmore']}">
                <span class="input-group-addon"><input type="color" name="cutmore_color" value="{$this_act['custom']['cutmore_color']}"></span>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">砍价按钮颜色</label>
        <div class="col-sm-9 col-xs-12">
            <div class="input-group" style="width: 200px">
                <input type="color" name="btn_color" value="{$this_act['custom']['btn_color']}">
            </div>
        </div>
    </div>

    <div class="form-group"></div>
    <div class="form-group">
        <label class="col-sm-2 control-label"></label>
        <div class="col-sm-9 col-xs-12">
            <input type="submit" value="提交" class="btn btn-primary">
            <input type="button" name="back" onclick="history.back()" style="margin-left:10px;" value="返回列表" class="btn btn-default">
        </div>
    </div>
</form>
{template '_footer'}